<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>发布房源</title>
	</head>
	<body>
		<h2>发布房源</h2>
		<a href="houseinfolist.jsp">返回首页</a>
		<form id="houseinfoForm" action="houseinfo/add" method="post">
			<table border="0">
				<tr>
					<td>房屋描述：</td>
					<td>
						<input type="text" name="houseDesc"/>
					</td>
				</tr>
				<tr>
					<td>户型：</td>
					<td>
						<select name="typeId">
						</select>
					</td>
				</tr>
				<tr>
					<td>租金：</td>
					<td>
						<input type="text" name="monthlyRent"/> 元/月
					</td>
				</tr>
				<tr>
					<th colspan="2">
						<input type="button" value="提交"/>
						<input type="reset" value="重置"/>
					</th>
				</tr>
			</table>
		</form>
	</body>
	<script type="text/javascript" src="statics/jquery-1.8.3.js"></script>
	<script type="text/javascript">
		$(function(){
			loadSelectData();
			$("input[value=提交]").click(function(){
				var houseDesc = $("input[name=houseDesc]").val().trim();
				var monthlyRent = $("input[name=monthlyRent]").val().trim();
				if (houseDesc == '') {
					alert('房屋描述必填');
					return;
				}
				if (monthlyRent == '') {
					alert('价格必填');
					return;
				} else if (Number.isNaN(Number(monthlyRent))){
					alert('租金格式错误');
					return;
				}
				$("#houseinfoForm").submit();
			});
		});
		function loadSelectData() {
			$.ajax({
				url : 'housetype/list',
				type : 'post',
				dataType : 'json',
				success : function(response){
					var datas = response;
					var strSelect = "";
					for (var i = 0; i < datas.length; i++) {
			strSelect+="<option value=\""+datas[i]['typeId']+"\">"+datas[i]['typeName']+"</option>";
					}
					$("select[name=typeId]").html(strSelect);
				}
			});
		}
	</script>
</html>
